﻿<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <script src="/js/header.js"></script>
    <title class="gettext">易付宝</title>
</head>
<body class="login-wbg" id="login">
    <section class="login-wrap">
        <div class="login-icon"><i></i></div>
        <div><p class="login-title gettext">卡管系统</p></div>
        <div class="login-cont">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        <label for="account" class="gettext">用户名</label>
                        <input type="text" name="account" class="form-control gettext" placeholder="用户名" autocomplete="off" />
                    </div>

                    <div class="col-md-12 p15_t">
                        <label for="password" class="gettext">密码</label>
                        <input type="password" name="password" class="form-control gettext" placeholder="密码" autocomplete="off" />
                    </div>

                    <div class="col-md-12 p15_t">
                        <label for="language" class="gettext">语言</label>
                        <select class="form-control gettext" name="language">
                            <option value="cn">中文</option>
                            <option value="en">English</option>
                        </select>
                    </div>

                    <div class="col-md-4 text-right"></div>
                    <div class="col-md-12 p20_t">
                        <button class="btn btn-block btn-primary btn-lg gettext" onclick="return login()">登录</button>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <script type="text/javascript">
        function login() {
            var language = $("select[name='language'] ").find("option:selected").val();

            var data = {
                "account": $("input[name='account']").val(),
                "password": $("input[name='password']").val(),
                "language": $("select[name='language']").find("option:selected").val()
            };

            var cover = FlashPay.UI.Mask({
                obj: $("#login"),
                opacity: 0.5
            });

            $.post("/account/Login", data, function (a) {
                if (a.success) {
                    var username = a.data.userName;
                    var isLogged = a.data.uLoggedIn;
                    var isShowQR = a.data.uShowQR;
                    if (isLogged == 1) {
                        var key = a.data.uSecretKey;
                        var userid = a.data.userId;
                        var height = 340;
                        if (isShowQR == 1) height = 80;
                        var url = "/secondlogin.html?username=" + username + "&secret=" + key + "&isLogged=" + isLogged + "&isShowQR=" + isShowQR +"&userId=" + userid;
                        FlashPay.UI.DialogOpen(encodeURI(url), {
                            title: "验证动态口令",
                            width: 500,
                            height: height,
                            init: function () {
                                this.button(
                                    {
                                        name: "保存",
                                        callback: function () {
                                            var iframe = this.iframe.contentWindow;
                                            if (!iframe.document.body) {
                                                return false;
                                            }
                                            iframe.save();
                                            return false;
                                        },
                                        focus: true,
                                    },
                                    {
                                        name: '取消'
                                    }
                                );
                            }
                        });
                    } else {
                        $.removeCookie('username'); $.removeCookie('companyname'); $.removeCookie('token'); $.removeCookie('language');
                        FlashPay.UI.Tip_success("登录成功！");
                        $.cookie('username', username); $.cookie('companyname', a.data.companyName); $.cookie('token', a.data.token); $.cookie('language', data.language);$.removeCookie('popups');
                        window.location.href = "/index.html";
                    }
                } else {
                    FlashPay.UI.Tip_danger(a.errorMessage);
                }
                cover.Remove();
            });
        }

        $(document).keyup(function (event) {
            var keycode = event.which;
            if (keycode == 13) {
                login();
            }
        }); 

        $(function () {
            FlashPay.Util.Ajax({
                type: "Get",
                url: "/Account/CheckLogin",
                success: function (res) {
                    if (res.success) {
                        top.location.href = "/index.html";
                    } else {
                        $.removeCookie('username'); $.removeCookie('companyname'); $.removeCookie('token'); $.removeCookie('language');
                    }
                }
            });

            $("select[name='language']").change(function () {
                /* 設定一開始以哪個語系呈現 */
                $.i18n.setLocale($(this).val());

                /* 根據使用者目前語系更改文字內容，動態載入語系檔 */
                $._.replaceByLocale("/js/language/" + $._.getLocale() + ".json");
            });
        })
    </script>
</body>
</html>